//
//  MHNewMemberViewController.m
//  MiaoCircle
//
//  Created by Xuzhengrong on 2018/8/19.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHNewMemberViewController.h"
#import "MHNewMemberTableViewCell.h"
#import "MHNewMemberMessage.h"
#import "MHNewMemberViewModel.h"
#import "MHChatViewModel.h"
#import "MHMomentViewModel.h"
@interface MHNewMemberViewController ()
@property(nonatomic, strong)  MHNewMemberViewModel *viewModel;
@end

@implementation MHNewMemberViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView mh_registerNibCell:MHNewMemberTableViewCell.class];
    self.tableView.estimatedRowHeight= 85;
    self.tableView.rowHeight=UITableViewAutomaticDimension;
}


- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    return [tableView dequeueReusableCellWithIdentifier:@"MHNewMemberTableViewCell"];
}



- (void)configureCell:(MHNewMemberTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
    [cell bindViewModel:object];
    cell.avterImageView.tag = indexPath.row;
    cell.avterImageView.userInteractionEnabled = YES;
    [cell.avterImageView bk_whenTapped:^{
        MHNewMemberMessage *model = self.viewModel.datas[cell.avterImageView.tag];
        [[IMAPlatform sharedInstance] asyncGetStrangerInfo:[NSString stringWithFormat:@"%ld",(long)model.oprtUserId] succ:^(IMAUser *user) {
            IMAConversation *conversation =  [[IMAPlatform sharedInstance].conversationMgr chatWith:user];
            MHMomentViewModel *viewModel = [[MHMomentViewModel alloc] initWithServices:self.viewModel.services params:@{MHViewModelIsFootPrint:@(true),MHViewModelTitleKey:isEquaalCurrentUserId(user.userId)?@"我的足迹":@"Ta的足迹",MHViewModelConversation:conversation}];
            viewModel.userId = [user.userId intValue];
            viewModel.imUser = user;
            [self.viewModel.services pushViewModel:viewModel animated:YES];
        } fail:^(int code, NSString *msg) {
            
        }];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
